package com.tnxst.phexamination.public_health_docking_interface;

import com.tnxst.phexamination.constant.Trade;
import com.tnxst.phexamination.utils.ReflectUtils;
import com.tnxst.phexamination.utils.StringUtils;
import com.tnxst.phexamination.utils.WebServiceUtils;
import com.tnxst.phexamination.dto.HypertensionFollowDTO;

import java.util.LinkedHashMap;
import java.util.Map;

public class HypertensionInterface {

    /**
     * 58-1 查询个人高血压随访记录列表(通过ID)
     * @param pageSize
     * @param pageIndex
     * @param personId
     * @param response
     */
    public static void queryPersonalHypertensionFollowList(Integer pageSize, Integer pageIndex,
                                                           String personId, WebServiceUtils.Response response){
        String trade = Trade.HYPERTENSION.QUERY_PERSONAL_HYPERTENSION_FOLLOW_LIST;
        Map<String, Object> data = StringUtils.getPageDataMap(pageSize, pageIndex);
        if (StringUtils.isNotNull(personId))
            data.put("PersonID",personId);
        WebServiceUtils.call(trade,data,response);

    }

    /**
     * 58-2增加或修改高血压随访记录
     * @param hypertensionFollowDTO
     * @param orgId
     * @param response
     */
    public static void saveOrUpdateHypertensionFollow(HypertensionFollowDTO hypertensionFollowDTO, String orgId,
                                                      WebServiceUtils.Response response){
        String trade = Trade.HYPERTENSION.SAVE_OR_UPDATE_HYPERTENSION_FOLLOW;
        Map<String, Object> data = StringUtils.getDataMap();
        Map<String,Object> cmHyper = new LinkedHashMap<>();
        Map<String,Object> body = new LinkedHashMap<>();
        Map<String,Object> lifestyle = new LinkedHashMap<>();
        Map<String,Object> organ = new LinkedHashMap<>();
        Map<String, Object> transout = new LinkedHashMap<>();
        data.put("CmHyper",cmHyper);
        data.put("Body",body);
        data.put("Labora",hypertensionFollowDTO.getLabora());
        data.put("Lifestyle",lifestyle);
        data.put("Drug",hypertensionFollowDTO.getDrug());
        data.put("Organ",organ);
        data.put("transout",transout);
        data.put("Other",hypertensionFollowDTO.getOther());
        data.put("OrgID",orgId);
        fillHypertensionFollow(hypertensionFollowDTO,cmHyper,body,lifestyle,transout);
        WebServiceUtils.call(trade,data,response);

    }

    /**
     * $58-3 查询个人高血压随访记录(通过ID)
     * @param id
     * @param response
     */
    public static void queryPersonalHypertensionFollow(String id, WebServiceUtils.Response response){
        String trade = Trade.HYPERTENSION.QUERY_PERSONAL_HYPERTENSION_FOLLOW;
        Map<String, Object> data = StringUtils.getDataMap();
        data.put("ID",id);
        WebServiceUtils.call(trade,data,response);
    }

    /**
     * 填充高血压随访数据
     * @param hypertensionFollowDTO
     * @param cmHyper
     * @param body
     * @param lifestyle
     */
    private static void fillHypertensionFollow(HypertensionFollowDTO hypertensionFollowDTO, Map<String,Object> cmHyper,
                                               Map<String,Object> body, Map<String,Object> lifestyle, Map<String,Object> transout){
        String[] cmHyperNames = {"ID","PersonID","NextFollowUpDate","WayUp","Symptom","ExamBodyOther","NextWeight","NextHeartRate","NextSmoking",
                "NextDailyAlcohol","SaltIntake","NextSaltIntake","NextExerciseWeekTimes","NextExerciseWeekMinute","PsychologicalAdjustment",
                "ComplianceBehavior","MedicationCompliance","AdverseDrugReactions","FuClassification","FollowUpRemarks","FollowUpDate","DoctorName",
                "UserID","DoctorID"};
        String[] bodyNames = {"HeartRate","RightSbp","RightDbp","Height","Weight","Bmi"};
        String[] lifestyleNames = {"EachExerciseTime","ExerciseWeekTimes","Smoking","DailyAlcoholIntake"};
        String[] transoutNames = {"TargetOrgName","TranoutReasons"};
        ReflectUtils.objectToMap(cmHyperNames,hypertensionFollowDTO,cmHyper);
        ReflectUtils.objectToMap(bodyNames,hypertensionFollowDTO,body);
        ReflectUtils.objectToMap(lifestyleNames,hypertensionFollowDTO,lifestyle);
        ReflectUtils.objectToMap(transoutNames,hypertensionFollowDTO,transout);
    }
}
